package com.qf.lanzhou.shop.pojo.entity;

import com.qf.lanzhou.shop.pojo.qo.GoodsSizeQo;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author LEON-HE
 */
@Data
public class Goods {
    private Long id;
    private String name;
    private String content;
    private String summary;
    private BigDecimal originalPrice;
    private BigDecimal currentPrice;
    private String appearance;
    private String function;
    private String controlType;
    private String size;
    private String material;
    private String category;
    private Integer shelfStatus;
    private Integer eventStatus;
    private String headUrl;
    private Integer eventNum;
    private Integer totalNum;
    private String barCode;
    private Long sellerId;
    private Integer salesVolume;
    private String afterSale;
    private Timestamp updateTime;
    private Timestamp createTime;
    private String shopName;
    private SimpleDateFormat sdf;
    private String viewTime;
    private String timeDiff;

    private List<GoodsUrl> goodsUrlList;
    private List<GoodsSizeQo> goodsSizeQoList;

    public void setViewTime(Timestamp viewTime) {
        setTimeDiff(viewTime);
        sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String format = sdf.format(viewTime);
        this.viewTime = format;
    }

    public void setTimeDiff(Timestamp viewTime) {
        sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        String view = sdf.format(viewTime);
        String nowTime = sdf.format(new Date());
        Date before = null;
        Date now = null;
        try {
            before = sdf.parse(view);
            now = sdf.parse(nowTime);
            long between = now.getTime() - before.getTime();
            long day = between / (24 * 60 * 60 * 1000);
            long hour = (between / (60 * 60 * 1000) - day * 24);
            long min = ((between / (60 * 1000)) - day * 24 * 60 - hour * 60);
            long s = (between / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
            if (day != 0) {
                this.timeDiff = day + "天前";
                return;
            }
            if (hour != 0) {
                this.timeDiff = hour + "小时前";
                return;
            }
            if (min == 0) {
                this.timeDiff = "1分钟前";
                return;
            }
            this.timeDiff = min + "分钟前";
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

}
